home *** CD-ROM | disk | FTP | other *** search
- ###############################################################################
- # $Id: tools.tk,v 1.1 1994/02/18 20:29:45 bmott Exp $
- ###############################################################################
- # tools.tk - Routines to implement several useful routines
- #
- # Copyright 1993
- # Bradford W. Mott
- # November 19,1993
- ###############################################################################
- # $Log: tools.tk,v $
- # Revision 1.1 1994/02/18 20:29:45 bmott
- # Initial revision
- #
- ###############################################################################
-
-
- ###############################################################################
- # Dummy do nothing procedure
- ###############################################################################
- proc NOP {} {}
-
- ###############################################################################
- # Simple "child" dialog to get a value from the user
- ###############################################################################
- proc ChildEntryDialog {parent_window label regular_expression} {
- global ReturnValue
- global EntryDialogRegExp
- global EntryDialogParent
-
- set EntryDialogRegExp $regular_expression
- set EntryDialogParent $parent_window
-
- ## Just in case destroy the window
- catch {destroy $EntryDialogParent.entryDialog}
-
- ## Create the dialog frame
- frame $EntryDialogParent.entryDialog -relief raised -borderwidth 3
-
- ## Create the dialog label
- message $EntryDialogParent.entryDialog.message -text $label \
- -width 3i -justify left
-
- ## Create Entry field
- entry $EntryDialogParent.entryDialog.entry -width 20 -relief sunken
- $EntryDialogParent.entryDialog.entry icursor 0
- bind $EntryDialogParent.entryDialog.entry <Return> {
- set ReturnValue [$EntryDialogParent.entryDialog.entry get]
- if {[regexp $EntryDialogRegExp $ReturnValue]} {
- destroy $EntryDialogParent.entryDialog
- } else {
- ChildAlertDialog $EntryDialogParent \
- {The value you entered is not valid!!!}
- grab set $EntryDialogParent.entryDialog
- }
- }
-
- ## Create the OK and Cancel button field
- frame $parent_window.entryDialog.buttons
- button $EntryDialogParent.entryDialog.buttons.ok -text "Okay" \
- -command { set ReturnValue [$EntryDialogParent.entryDialog.entry get]
- if {[regexp $EntryDialogRegExp $ReturnValue]} {
- destroy $EntryDialogParent.entryDialog
- } else {
- ChildAlertDialog $EntryDialogParent \
- "The value you entered is not valid!!!"
- grab set $EntryDialogParent.entryDialog
- }
- }
- button $EntryDialogParent.entryDialog.buttons.cancel -text "Cancel" \
- -command {set ReturnValue ""; destroy $EntryDialogParent.entryDialog}
- pack $EntryDialogParent.entryDialog.buttons.ok -side left -expand 1 \
- -fill x -padx 4
- pack $EntryDialogParent.entryDialog.buttons.cancel -side right -expand 1 \
- -fill x -padx 4
-
- pack $EntryDialogParent.entryDialog.message -side top -fill x -pady 4 -padx 4
- pack $EntryDialogParent.entryDialog.entry -side top -fill x -pady 4 -padx 4
- pack $EntryDialogParent.entryDialog.buttons -side top -fill x -pady 4
-
- place $EntryDialogParent.entryDialog -relx 0.5 -rely 0.5 -anchor center
-
- ## Make this a modal dialog
- tkwait visibility $EntryDialogParent.entryDialog
- focus $EntryDialogParent.entryDialog.entry
- grab set $EntryDialogParent.entryDialog
- tkwait window $EntryDialogParent.entryDialog
-
- return $ReturnValue
- }
-
- ###############################################################################
- # Bring up a "child" alert dialog with the given message
- ###############################################################################
- proc ChildAlertDialog {parent_window the_message} {
- global AlertDialogParent
-
- set AlertDialogParent $parent_window
-
- ## Just in case destroy the window
- catch {destroy $AlertDialogParent.alertDialog}
-
- frame $AlertDialogParent.alertDialog -relief raised -borderwidth 3
-
- label $AlertDialogParent.alertDialog.label -bitmap warning -relief ridge \
- -padx 8 -pady 8 -borderwidth 3
- message $AlertDialogParent.alertDialog.message -text $the_message \
- -width 3i -justify left
- button $AlertDialogParent.alertDialog.button -text "Okay" \
- -command {destroy $AlertDialogParent.alertDialog}
-
- pack $AlertDialogParent.alertDialog.label -side left -padx 8 -pady 8
- pack $AlertDialogParent.alertDialog.message -side top -padx 4 -pady 8
- pack $AlertDialogParent.alertDialog.button -side top -fill x -padx 4 -pady 4
-
- place $AlertDialogParent.alertDialog -relx 0.5 -rely 0.5 -anchor center
-
- ## Make this a modal dialog
- tkwait visibility $AlertDialogParent.alertDialog
- grab set $AlertDialogParent.alertDialog
- tkwait window $AlertDialogParent.alertDialog
- }
-
-
- ###############################################################################
- # Simple "toplevel" dialog to get a value from the user
- ###############################################################################
- proc EntryDialog {label window_title regular_expression} {
- global ReturnValue
- global EntryDialogRegExp
-
- set EntryDialogRegExp $regular_expression
-
- ## Just in case destroy the window
- catch {destroy .entryDialog}
-
- ## Create a toplevel window
- toplevel .entryDialog
- wm title .entryDialog $window_title
- wm iconname .entryDialog $window_title
-
- ## Create the dialog label
- message .entryDialog.message -text $label -width 3i -justify left
-
- ## Create Entry field
- frame .entryDialog.value -relief ridge -borderwidth 2
- entry .entryDialog.value.entry -width 10
- bind .entryDialog.value.entry <Return> {
- set ReturnValue [.entryDialog.value.entry get]
- if {[regexp $EntryDialogRegExp $ReturnValue]} {
- destroy .entryDialog
- } else {AlertDialog {That is not a valid value!!!}}
- }
- pack .entryDialog.value.entry -side left -fill x -expand 1 -padx 4
-
- ## Create the OK and Cancel button field
- frame .entryDialog.buttons
- button .entryDialog.buttons.ok -text "Okay" \
- -command { set ReturnValue [.entryDialog.value.entry get]
- if {[regexp $EntryDialogRegExp $ReturnValue]} {
- destroy .entryDialog
- } else {AlertDialog {That is not a valid value!!!}}
- }
- button .entryDialog.buttons.cancel -text "Cancel" \
- -command {set ReturnValue ""; destroy .entryDialog}
- pack .entryDialog.buttons.ok -side left -expand 1 -fill x -padx 4
- pack .entryDialog.buttons.cancel -side right -expand 1 -fill x -padx 4
-
- pack .entryDialog.message -side top -fill x -pady 4 -padx 4
- pack .entryDialog.value -side top -fill x -pady 4 -padx 4
- pack .entryDialog.buttons -side top -fill x -pady 4
-
- ## Make this a modal dialog
- tkwait visibility .entryDialog
- grab set .entryDialog
- tkwait window .entryDialog
-
- return $ReturnValue
- }
-
- ###############################################################################
- # Bring up a "toplevel" alert dialog with the given message
- ###############################################################################
- proc AlertDialog {the_message} {
-
- ## Just in case destroy the window
- catch {destroy .alertDialog}
-
- toplevel .alertDialog
- wm title .alertDialog "Alert Dialog"
- wm iconname .alertDialog "Alert Dialog"
-
- label .alertDialog.label -bitmap warning -relief ridge -padx 8 -pady 8 \
- -borderwidth 3
- message .alertDialog.message -text $the_message -width 2.5i -justify left
- button .alertDialog.button -text "Okay" -command {destroy .alertDialog}
-
- pack .alertDialog.label -side left -padx 8 -pady 8
- pack .alertDialog.message -side top -padx 4 -pady 4
- pack .alertDialog.button -side top -fill x -padx 4 -pady 4
-
- ## Make this a modal dialog
- tkwait visibility .alertDialog
- grab set .alertDialog
- tkwait window .alertDialog
- }
-
-